package cn.shiwei.order.controller;

import cn.shiwei.basic.exception.MyException;
import cn.shiwei.basic.util.RequestStatus;
import cn.shiwei.order.service.IOrderPetService;
import cn.shiwei.order.dto.OrderDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderPetService orderPetService;

    @PostMapping("create")
    public RequestStatus ssaveOrder(@RequestBody Map<String, Long> map) {
        try {
            String sn  = orderPetService.saveOrder(map);
            return RequestStatus.me().setResultObj(sn);
        } catch (MyException e) {
            e.printStackTrace();
            return RequestStatus.me().setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return RequestStatus.me().setMessage("系统异常");
        }
    }

    @PutMapping("/save") // 保存订单演示, 添加成功, 生成一个订单, 生成一个地址, 生成了两个订单详情 ok,   前端页面没做
    public RequestStatus saveOrder(@RequestBody OrderDto dto){
        try {
            String sn  = orderPetService.saveOrder(dto);
            return RequestStatus.me().setResultObj(sn);
        } catch (MyException e) {
            e.printStackTrace();
            return RequestStatus.me().setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return RequestStatus.me().setMessage("系统异常");
        }
    }
}
